<?php
include('../data/comm.inc.php');
include('../data/myadminvar.php');
include('../func/func.php');
include('../func/csfunc.php');

include('../func/adminfunc.php');
include('../include.php');
include('./checklogin.php');
switch ($_REQUEST['xtype']) {
    case "Bigscreen":
        $game = getgamecs($userid);
        $game = getgamename($game);
        if (in_array($_REQUEST['gid'], $garr)) {
            $gid = $_REQUEST['gid'];
        }
        $msql->query("select * from `$tb_game` where gid='$gid'");
        $msql->next_record();
        $ftype = json_decode($msql->f('ftype'), true);
        
        $gname = $msql->f('gname');
		$flname = $msql->f('flname');
		$warn  = array();
        foreach ($ftype as $key => $val) {
            $warn[$key]['name'] = $val['name'];
            $fsql->query("select je,ks,htime1,htime2,stime1,stime2,je1,je2,jq1,jq2,bhtime1,bhtime2 from `$tb_warn` where userid='$userid' and gid='$gid' and class='$key'");
            $fsql->next_record();
            $warn[$key]['ftype'] = $key;
            $warn[$key]['htime1']    = $fsql->f('htime1') ? $fsql->f('htime1') : '';
            $warn[$key]['htime2']    = $fsql->f('htime2') ? $fsql->f('htime2') : '';
            $warn[$key]['stime1']    = $fsql->f('stime1') ? $fsql->f('stime1') : '';
            $warn[$key]['stime2']    = $fsql->f('stime2') ? $fsql->f('stime2')  : '';
            $warn[$key]['bhtime1']    = $fsql->f('bhtime1') ? $fsql->f('bhtime1')  : '';
            $warn[$key]['bhtime2']    = $fsql->f('bhtime2') ? $fsql->f('bhtime2')  : '';
            $warn[$key]['je1']    = $fsql->f('je1') ? $fsql->f('je1')  : '';
            $warn[$key]['je2']    = $fsql->f('je2') ? $fsql->f('je2')  : '';
            $warn[$key]['jq1']    = $fsql->f('jq1') ? $fsql->f('jq1')  : '';
            $warn[$key]['jq2']    = $fsql->f('jq2') ? $fsql->f('jq2')  : '';
            $warn[$key]['gname'] = $gname;
        }
	    $tpl->assign("config", $config);
        $tpl->assign('fly', $fly);
		$tpl->assign('nums', floor(count($warn)/2));
        $tpl->assign("gid", $gid);
		$tpl->assign("flname", $flname);
		$tpl->assign("game", $game);
        $tpl->assign("cs", $warn);//print_r($warn);die();
        $tpl->display("Bigscreen.html");
        break;
    case "savaBigscreen":
        $gid = $_POST['gid'];
        $data = $_POST;
        for ($i = 0; $i <= 46; $i++) {
            if (isset($data['htime1' . $i]) && isset($data['stime1' . $i]) && isset($data['je1' . $i]) && isset($data['jq1' . $i]) && isset($data['htime2' . $i]) && isset($data['stime2' . $i]) && isset($data['je2' . $i]) && isset($data['jq2' . $i])) {
                $htime1 = $data['htime1' . $i];
                $stime1 = $data['stime1' . $i];
    			$htime2 = $data['htime2' . $i];
                $stime2 = $data['stime2' . $i];
    			$je1 = $data['je1' . $i];
                $jq1 = $data['jq1' . $i];
                $je2 = $data['je2' . $i];
                $jq2 = $data['jq2' . $i];

                $bhtime1 = 0;
                if($htime1 && $stime1 && $je1 && $jq1)
                {
                    $bhtime1 = 1;
                }
                $bhtime2 = 0;
                if($htime2 && $stime2 && $je2 && $jq2)
                {
                    $bhtime2 = 1;
                }
                // 构建SQL更新语句
                $sql = "UPDATE `$tb_warn` SET 
                    htime1='$htime1',
                    stime1='$stime1',
    				htime2='$htime2',
                    stime2='$stime2',
                    je1='$je1',
                    jq1='$jq1',
    				je2='$je2',
                    jq2='$jq2',
                    bhtime1 = '$bhtime1',
                    bhtime2 = '$bhtime2'
                    WHERE userid='$userid' AND gid='$gid' AND class='$i'";
                $res = $msql->query($sql);
                if (!$res) {
                    $sql = "insert into  `$tb_warn` SET 
                    htime1='$htime1',
                    stime1='$stime1',
    				htime2='$htime2',
                    stime2='$stime2',
                    je1='$je1',
                    jq1='$jq1',
    				je2='$je2',
                    jq2='$jq2',
                    userid='$userid',
                    gid='$gid',
                    class='$i'";
                    $msql->query($sql);
                }
            }
        }
        echo 1;
        break;
    case "cancelBigscreen":
        $gid = $_POST['gid'];
        $data = $_POST;
        for ($i = 0; $i <= 46; $i++) {
            $htime1 = '';
            $stime1 = '';
			$htime2 = '';
            $stime2 = '';
			$je1 = '';
            $jq1 = '';
            $je2 = '';
            $jq2 = '';
            $bhtime1 = 0;
            $bhtime2 = 0;

            // 构建SQL更新语句
            $sql = "UPDATE `$tb_warn` SET 
                htime1='$htime1',
                stime1='$stime1',
				htime2='$htime2',
                stime2='$stime2',
                je1='$je1',
                jq1='$jq1',
				je2='$je2',
                jq2='$jq2',
                bhtime1 = 0,
                bhtime2 = 0
                WHERE userid='$userid' AND gid='$gid' AND class='$i'";
            $msql->query($sql);
        }
        echo 1;
        break;
}
?>